package config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServerConfig {

	/**
	 * 服务器配置的储存容器
	 */
	private static Map<String, String> save = new HashMap<String, String>();
	
	private static final Logger logger = LoggerFactory.getLogger(ServerConfig.class); 
	
	public static boolean initConfig()
	{
		File file = new File("config/server.ini");
		BufferedReader reader = null;
		try 
		{
			reader = new BufferedReader(new FileReader(file));
			String tempString = null;
			while ((tempString = reader.readLine()) != null) 
			{
			    if(tempString.indexOf("#") == -1)//以#开始的都是注释
			    {
			    	tempString = tempString.replace(";", "");
			    	tempString = tempString.replaceAll(" ", "");
			    	String[] result = tempString.split("=");
			    	save.put(result[0], result[1]);
			    }
			}
			reader.close();
	     } 
		 catch (IOException e) 
		 {
			 logger.error("Loading server.ini error!!");
			 e.printStackTrace();
			 return false;
		 } 
		return true;
	}
	
	/**
	 * 取得配置文件的值
	 * @param key
	 * @return
	 */
	public static String getValue(String key)
	{
		return save.get(key);
	}
	
}
